/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2022-2022. All rights reserved.
 */

import { initByProject, initExecuteCommand, runHvigor } from '../src/common/common';

describe('test the user defined task',()=>{
  test.concurrent('test module task ',async ()=>{
    await initByProject('common-test', async (projectDir) => {
      const command = initExecuteCommand({
        tasks: 'task2'
      });
      const result = await runHvigor(projectDir, command);
      expect(result.stdout.includes('BUILD SUCCESSFUL')).toBeTruthy();
      expect(result.stdout.includes('Disabled :module1:task1...')).toBeTruthy();
      expect(result.stdout.includes('This is a default task')).toBeTruthy();
    });
  });

  test.concurrent('test module task depends project task',async ()=>{
    await initByProject('common-test', async (projectDir) => {
      const command = initExecuteCommand({
        tasks: 'test'
      });
      const result = await runHvigor(projectDir, command);
      expect(result.stdout.includes('BUILD SUCCESSFUL')).toBeTruthy();
      expect(result.stdout.includes('This is a test task')).toBeTruthy();
      expect(result.stdout.includes('Finished ::clean...')).toBeTruthy();
      expect(result.stdout.includes('Finished :module1:clean...')).toBeTruthy();
    });
  });

  test.concurrent('test module task in hvigorfile.ts',async ()=>{
    await initByProject('common-test-ts', async (projectDir) => {
      const command = initExecuteCommand({
        tasks: 'task2'
      });
      const result = await runHvigor(projectDir, command);
      expect(result.stdout.includes('BUILD SUCCESSFUL')).toBeTruthy();
      expect(result.stdout.includes('Disabled :module1:task1...')).toBeTruthy();
      expect(result.stdout.includes('This is a default task')).toBeTruthy();
    });
  });

  test.concurrent('test module task depends project task in hvigorfile.ts',async ()=>{
    await initByProject('common-test-ts', async (projectDir) => {
      const command = initExecuteCommand({
        tasks: 'test'
      });
      const result = await runHvigor(projectDir, command);
      expect(result.stdout.includes('BUILD SUCCESSFUL')).toBeTruthy();
      expect(result.stdout.includes('This is a test task')).toBeTruthy();
      expect(result.stdout.includes('Finished ::clean...')).toBeTruthy();
      expect(result.stdout.includes('Finished :module1:clean...')).toBeTruthy();
    });
  });
});
